package com.kwm;

import java.util.Random;

public class demo1 {
    public static void main(String[] args) {

        Random random = new Random();
        int count = 0;
        // 控制每行显示的算式数量
        int Line = 10;

        while (count < 50) {
            // 随机决定是加法还是减法，0 表示加法，1 表示减法
            int isAddition = random.nextInt(2);

            if (isAddition == 0) {
                // 生成加法的两个加数，确保和不超过 100
                int num1 = random.nextInt(101);
                int num2 = random.nextInt(101 - num1);
                int sum = num1 + num2;
                System.out.printf("%s+%s=%s",String.format("%2d",num1),String.format("%2d",num2),String.format("%2d",sum)+'\t');
            } else {
                // 生成减法的被减数和减数，确保差不小于 0
                int num1 = random.nextInt(101);
                int num2 = random.nextInt(num1 + 1);
                int diff = num1 - num2;
                System.out.printf("%s-%s=%s",String.format("%2d",num1),String.format("%2d",num2),String.format("%2d",diff)+'\t');
            }

            count++;
            // 每行显示指定数量的算式后换行
            if (count % Line == 0) {
                System.out.println();
            }
        }
    }
}
